<?php
    $key = $_GET['key'];
    // print_r ($key);
    $con = mysqli_connect('localhost','root','123456','goodslist');

    $sql="SELECT * FROM `goods` WHERE `goods_name` LIKE '%$key%' ";

    $row = mysqli_query($con,$sql);

    if(!$row){
        die('error' . mysqli_error($con));
    }

    $arr= array();
    $res = mysqli_fetch_assoc($row);
    if(!$res){
        die(json_encode('error:没有这商品'));
    }
    while($res){
        array_push($arr,$res);
        $res = mysqli_fetch_assoc($row);
    }
    // echo '111';
    // print_r (json_encode($arr,JSON_UNESCAPED_UNICODE));
    
    echo json_encode(array("code"=>1,"message"=>"查询成功"  ,"list"=>$arr),JSON_UNESCAPED_UNICODE)
?>